import { ftMenuData } from '@/service/modules/home';
import { Effect, Reducer } from 'umi';

export interface IHomeModelState {
  menuData: any;
}
export interface IHomeModelType {
  state: IHomeModelState;
  effects: {
    queryMenu: Effect;
  };
  reducers: {
    setState: Reducer<IHomeModelState>;
  };
}

const model: IHomeModelType = {
  state: {
    menuData: [],
  },
  effects: {
    *queryMenu({}, { call, put }) {
      // 使用接口
      const { banner } = yield call(ftMenuData);
      const { list } = banner;
      yield put({
        type: 'setState',
        payload: {
          menuData: list || [],
        },
      });
    },
  },
  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};

export default model;
